import matplotlib.pyplot as plt
import numpy as np
import os

def cr():
    x_data = ['MID', 'EDF', 'INS', 'SRPT', 'FB', 'THR', 'OPTFB', 'RM', 'SEDF', 'SALL', 'FIFO', 'FEDF']
    cr_data = [0.8265522917647484, 0.980252468812955, 0.9820775004917054, 0.8396306043319458, 0.9788232819694158, 0.9788232819694158, 0.9777697877034235, 0.9382645597252832, 0.9709189443674886, 0.8302501421740448, 0.3655157285281486, 0.36593847358397097]
    plt.bar(x_data,cr_data,color="deepskyblue",label="Average Completion Rate")

    #line
    ave_us_data = [0.7579864000000004, 0.8808456000000001, 0.8815849999999998, 0.7696546000000004, 0.8799038, 0.8799038, 0.8791284, 0.8565044000000002, 0.8711182, 0.7657729999999999, 0.39288760000000017, 0.39087799999999995]
    worst_us_data = [0.73879, 0.87426, 0.87974, 0.7367, 0.87438, 0.87438, 0.87144, 0.84824, 0.862, 0.73856, 0.3734, 0.3722]
    ave_Comp_ratio = [0.840153402793172, 0.9763307470627355, 0.9771502992684548, 0.853086455331412, 0.9752868543560186, 0.9752868543560186, 0.9744273996896474, 0.9493509199733984, 0.965548880514298, 0.8487840833518067, 0.43547727776546225, 0.43324983373974746]
    worst_Comp_ratio = [0.8188760806916426, 0.9690312569275106, 0.9751052981600532, 0.8165595211704721, 0.969164265129683, 0.969164265129683, 0.9659055641764576, 0.9401906450897806, 0.9554422522722235, 0.8186211483041455, 0.41387718909332744, 0.41254710707160275]
    plt.plot(x_data, ave_us_data, color = "sandybrown", marker='>', ms=3, label="ave_us")
    plt.plot(x_data, worst_us_data, color = "crimson", marker='o', ms=3, linestyle='-.', label="worst_us")
    plt.plot(x_data, ave_Comp_ratio, color = "plum", marker='*', ms=3, label="ave_compratio")
    plt.plot(x_data, worst_Comp_ratio, color = "indigo", marker='o', ms=3,linestyle='--', label="worst_compratio")
    plt.legend()
    plt.title('Completion rate & US & CompRatio')
    graph_path = os.path.dirname(os.path.abspath(__file__)) + '/graph/'
    if not os.path.isdir(graph_path):
        os.makedirs(graph_path)
    file_name = graph_path + __file__.split('/')[-1].split('.')[0]
    plt.savefig(f"{file_name}.pdf", bbox_inches='tight')
    plt.close()


if __name__ == '__main__':
    cr()
        
